$(function () {
    // var loading = weui.loading('loading', {
    //     className: 'custom-classname'
    // });
    var result = Model.order.buyerOrder({
        state: 2
    });
    // if (!sessionStorage.getItem('hmdj_stopError')) {
    //     sessionStorage.setItem('hmdj_stopError', true);
    // } else {
    //     if (result.code) {
    //         Common.fn.formatOutput(result);
    //         loading.hide();
    //         return false;
    //     }
    // }
    // if (result.code == 1) {
    //     loading.hide();
    // }


    for (var i = 0; i < result.data.length; i++) {
        if (result.ordermessages[i].state = 1) {
            result.ordermessages[i].message = "付款成功";
        }

        var item = ' <div class="order-list" data-id="' + result.ordermessages[i].id + '">' +
            '        <div class="weui-cell">' +
            '            <div class="weui-cell__bd weui-cell_access shop-name">' +
            '                <img src="' + result.users[i].photo + '" class="user-head-image min-head-img">' +
            '                <span>' + result.users[i].nickname + '</span>' +
            '            </div>' +
            '            <div class="weui-cell__ft">' + result.ordermessages[i].message + '</div>' +
            '        </div>' +
            '        <div class="weui-cell order-detail-info" data-id="' + result.ordermessages[i].id + '">' +
            '            <div class="weui-cell__hd"><img src="' + ((result.goods[i].goodsImg.length > 0) ? result.goods[i].goodsImg[0].image : '') + '" class="shop-img"></div>' +
            '            <div class="weui-cell__bd good-name">' + result.goods[i].content + '</div>' +
            '            <div class="weui-cell__ft">' + result.ordermessages[i].count + '*' + result.goods[i].price + '</div>' +
            '        </div>' +
            '        <div class="order-btn-container">' +
            '            <a class="weui-btn weui-btn_mini weui-btn_default order-btn js-comfrim-receive"  data-id="' + result.ordermessages[i].orderId + '" goods-id="' + result.goods[i].id + '">确认收货</a>' +
            '        </div>' +
            '    </div>';
        $('.order-container').append(item);
    }
    if (result.data.length == 0) {
        $('.order-container').append('<p style="text-align: center; color: #666;">暂无订单</p>');
    }
});
/* $(document).on('click', '.access-list', function () {
    var orderId = $(this).attr('data-id');
    location.href = 'order_buyer_detail.html?oid=' + orderId;
});
 */
// 收货按钮

$(document).on('click', '.order-detail-info', function () {
    var orderId = $(this).attr('data-id');
    location.href = 'order_buyer_detail.html?id=' + orderId;
});
$(document).on('mousedown', '.btn-order-pay', function () {
    var orderId = $(this).attr('data-id');
    Common.fn.getForOrder(orderId);
});


$(document).on('click', '.js-comfrim-receive', function () {
    var orderid = $(this).attr('data-id');
    var goodsid = $(this).attr('goods-id');

    var confirms = weui.confirm(
        "要确认收货么？",
        function () {
            var result2 = Model.order.perUpdateOrder({
                state: 3,
                id: orderid,
                goodsid: ""

            });
            if (result2.code = 1) {
                weui.toast('确认收货成功', {
                    duration: 1500,
                    className: 'custom-classname',
                });
            }
            location.reload();
        },
        function () {
        }
    );

});

